package com.cater.sys.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.JsonDataDao;
import com.cater.sys.entity.JsonData;
import com.cater.sys.service.BaseService;

/**
 * @author 作者: sd
 *  @公用自定义字段
 * @version 1.0
 */
@Service
public class JsonDataServiceImpl implements BaseService<JsonData, CommonQuery, String> {

	@Autowired
	private JsonDataDao dao;

	@Override
	public PageResult<JsonData> findPageResult(CommonQuery query) {
		PageResult<JsonData> result = new PageResult<JsonData>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<JsonData> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<JsonData> getAll() {
		return dao.getAll();
	}

	@Override
	public List<JsonData> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}


	@Override
	public int save(JsonData t) {
		t.setId(UUID.randomUUID().toString());
		return  dao.save(t);
	}
	
	public String saves(JsonData t) {
		t.setId(UUID.randomUUID().toString());
		 dao.save(t);
		return t.getId();
	}

	@Override
	public void update(JsonData t) {
		dao.update(t);
	}


	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public JsonData getById(String id) {
		return dao.getById(id);
	}
}
